script_enemy_main{

let startangle=rand(0,360);
let soundpause=0;

let shot1=0;
let bullet1=[];
let timer1=[];
let bounce1=[];
let direction1=[];
let id1=[];

let character="Nanami";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=45;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshotb6=("\script\SoundEffects\shotb6.wav");
let SEmagics5=("\script\SoundEffects\magics5.wav");

let BG1=("\script\Images\BackgroundLayers\Nanami1.png");
let BG2=("\script\Images\BackgroundLayers\Nanami2.png");
let GRboss=("\script\Images\CharacterSprites\Nanami.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsNanami1.txt");
	
	LoadSE("\script\SoundEffects\shotb6.wav");
	LoadSE("\script\SoundEffects\magics5.wav");

	LoadGraphic("\script\Images\CharacterSprites\Nanami.png");
	LoadGraphic("\script\Images\BackgroundLayers\Nanami1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Nanami2.png");

	SetScore(500000);
	SetLife(300);
	SetTimer(45);
	SetInvincibility(120);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);

	SetCommonData("Boss1Vanish",1);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(64,64,64,64);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=5; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Dessert [All Flavors Of Gelato]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+100){
	SetMovePosition01(GetPlayerX+rand(100,130),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-100){
	SetMovePosition01(GetPlayerX-rand(100,130),rand(miny+60,miny+120),1.5);
	}
}


if(time%100==0 && time>=60){
let angle=rand(0,360);
let speed=4;
let color=rand_int(1,10);
let nr=1;
	loop(2){
		loop(18){
		shot1=(Obj_Create(OBJ_SHOT));
		Obj_SetPosition(shot1,GetX,GetY);
		Obj_SetAngle(shot1,angle);
		Obj_SetSpeed(shot1,speed);
		ObjShot_SetGraphic(shot1,color);
		bullet1=bullet1~[shot1];
		timer1=timer1~[shot1];
		timer1[length(bullet1)-1]=0;
		bounce1=bounce1~[shot1];
		bounce1[length(bullet1)-1]=0;
		direction1=direction1~[shot1];
		direction1[length(bullet1)-1]=90+45*cos(startangle/1.5);
		id1=id1~[shot1];
		id1[length(bullet1)-1]=nr;
		angle+=360/18;
		}
	nr=0;
	angle+=360/36;
	speed-=1.2;
	}
PlaySE(SEshotb6);
}

if(time>=60){
let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i); bounce1=erase(bounce1,i); direction1=erase(direction1,i); id1=erase(id1,i);
		i--;
		}
		else{
		if(timer1[i]<60 && Obj_GetSpeed(bullet1[i])>0){ Obj_SetSpeed(bullet1[i],Obj_GetSpeed(bullet1[i])-0.08); }
		if(Obj_GetSpeed(bullet1[i])<0){ Obj_SetSpeed(bullet1[i],0); }
		if(timer1[i]==60){ Obj_SetAngle(bullet1[i],direction1[i]); }
		if(timer1[i]>=60 && Obj_GetSpeed(bullet1[i])<1.5){ Obj_SetSpeed(bullet1[i],Obj_GetSpeed(bullet1[i])+0.03); }
			if(bounce1[i]<1 && id1[i]==0){
			let angletoplayer=atan2(GetPlayerY-Obj_GetY(bullet1[i]),GetPlayerX-Obj_GetX(bullet1[i]));
				if(Obj_GetX(bullet1[i])<=minx || Obj_GetX(bullet1[i])>=maxx || Obj_GetY(bullet1[i])>=maxy){
				Obj_SetAngle(bullet1[i],angletoplayer+rand(-4,4));
				Obj_SetSpeed(bullet1[i],2);
				bounce1[i]=bounce1[i]+1;
				if(soundpause==0){ PlaySE(SEmagics5); soundpause=4; }
				}
			}
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
}
if(soundpause>0){ soundpause--; }

startangle++;
time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<120){ bgfade+=5; }

	SetGraphicRect(0,0,588,588);
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(255);
	SetColor(bgfade,bgfade,bgfade);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time/3);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.4,1.4);
	SetTexture(BG2);
	SetGraphicAngle(0,0,(-time/3));
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,5);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}